package rdd01.action

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark_Action {
  def main(args: Array[String]): Unit = {
    val sparkConf=new SparkConf().setMaster("local[*]").setAppName("wordCount")
    val sc=new SparkContext(sparkConf)
    wordcount1(sc)

    sc.stop()
  }
  def wordcount1(sc:SparkContext):Unit={
    val rdd=sc.makeRDD(List("Hello Scala","Hello Spark"),2)
    val words: RDD[String] = rdd.flatMap(_.split(" "))
    val group: RDD[(String, Iterable[String])] = words.groupBy(word => word)
    val wordCount: RDD[(String, Int)] = group.mapValues(iter => iter.size)
    wordCount.collect().foreach(println)
    wordCount.saveAsTextFile("test")
  }

}
